<template>
  <div class="tab-control">
    <div
      v-for="(item, index) in tabTitle"
      :key="index"
      class="tab-control-item"
      :class="{ active: index == currentIndex }"
      @click="itemClick(index)"
    >
      <span> {{ item }} </span>
    </div>
  </div>
</template>

<script>
import { ref } from "vue";
export default {
  name: "TabControl",
  props: {
    tabTitle: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  setup(props, { emit }) {
    let currentIndex = ref(0);
    const itemClick = (index) => {
      currentIndex.value = index;
      emit("tabClick", index);
    };
    return {
      currentIndex,
      itemClick,
    };
  },
};
</script>

<style lang='less'>
@import "@/assets/css/base.less";
.tab-control {
  display: flex;
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  background-color: yellow;
  width: 100%;

  z-index: 10; // 防止滑动的时候被下面的内容遮挡

  //sticky是css3新增属性，控制当选项卡一直向上滑动时固定在某一部位
  position: sticky;
  top: 45px;

  .tab-control-item {
    flex: 1;
    span {
      padding: 6px;
    }
  }
  .active {
    color: @color-high-text;
    span {
      border-bottom: 3px solid @color-high-text;
    }
  }
}
</style>